/*
 * Project: BoboDesignPattern
 * 
 * File Created at 2019年9月16日
 * 
 * Copyright 2012 Greenline.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Greenline Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Greenline.com.
 */
package test.scattered2.myrpc.client;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

import test.scattered2.myrpc.server.RPCRequest;

/**
 * @Type RemoteInvocationHandler
 * @Desc
 * @author 52489
 * @date 2019年9月16日
 * @Version V1.0
 */
public class RemoteInvocationHandler implements InvocationHandler {
    String host;
    Integer port;

    public String getHost() {
        return host;
    }

    public void setHost(String host) {
        this.host = host;
    }

    public Integer getPort() {
        return port;
    }

    public void setPort(Integer port) {
        this.port = port;
    }

    /**
     * @param host
     * @param port2
     */
    public RemoteInvocationHandler(String host, Integer port) {
        super();
        this.host = host;
        this.port = port;
    }

    /*
     * (non-Javadoc)
     * 
     * @see java.lang.reflect.InvocationHandler#invoke(java.lang.Object,
     * java.lang.reflect.Method, java.lang.Object[])
     */
    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        RPCRequest request = new RPCRequest();
        request.setMethodName(method.getName());
        request.setParameters(args);
        RPCNetTransport rpcNetTransport = new RPCNetTransport(host, port);
        return rpcNetTransport.sendRequest(request);
    }

}
